package com.bgs.travelapp.order.controller;

import com.alipay.api.AlipayApiException;
import com.bgs.travelapp.order.entity.ScenicOrderEntity;
import com.bgs.travelapp.order.service.PurchaseService;
import com.bgs.travelapp.result.CommonResult;
import com.bgs.travelapp.userRealBinds.entity.UserRealBindsEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 购买门票
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/orders/ticket")
public class PurchaseController {

    @Resource
    PurchaseService purchaseService;

    /**
     * 询问订单状态（前端展示）
     * lzy 2022-8-16 09点41分
     * @param code
     * @return
     */
    @GetMapping("/queryOrderStatus")
    public CommonResult queryOrderStatus(String code) throws AlipayApiException {
        return purchaseService.queryOrderStatus(code);
    }

    /**
     * 加入订单信息到redis中，并开始计时600秒后若无操作自动清除（前端展示）
     * fys 2022.8.2 11点46分
     * @param scenicTicket
     * @return
     */
    @PostMapping("/saveScenicticket")
    public CommonResult saveScenicticket(ScenicOrderEntity scenicTicket) throws AlipayApiException, ParseException {
        return CommonResult.ok(purchaseService.saveScenicticket(scenicTicket));
    }

    /**
     * 订单付款，将redis中缓存的数据取出，并进行更改状态付款处理（前端展示）
     * fys 2022.8.2 11点46分
     * @param scenicTicket
     * @return
     */
    @PostMapping("/updateScenicticketStatus")
    public CommonResult UpdateScenicticketStatus(ScenicOrderEntity scenicTicket){
        System.out.println(scenicTicket);
        return CommonResult.ok(purchaseService.UpdateScenicticketStatus(scenicTicket));
    }

    /**
     * 订单付款，将redis中缓存的数据取出，并进行更改状态付款处理（前端展示）
     * fys 2022.8.2 11点46分
     * @param scenicTicket
     * @return
     */
    @PostMapping("/updateScenicticketStatus1")
    public CommonResult UpdateScenicticketStatus1(ScenicOrderEntity scenicTicket){
        return CommonResult.ok(purchaseService.UpdateScenicticketStatus1(scenicTicket));
    }

    /**
     * 询问订单状态是否呗支付（前台展示）
     * lzy 2022-8-22 21点02分
     * @param code
     * @return
     */
    @GetMapping("/getOrderQuery")
    public CommonResult getOrderQuery(String code) throws AlipayApiException {
        return purchaseService.getOrderQuery(code);
    }


}
